//
//  LaunchViewController.m
//  Snigger
//
//  Created by 火火火火火 on 16/8/19.
//  Copyright © 2016年 Smile. All rights reserved.
//

#import "LaunchViewController.h"
#import "RootTabBarController.h"

#define LeeScreen_Frame ([UIScreen mainScreen].bounds)
#define LeeScreen_Width ([UIScreen mainScreen].bounds.size.width)
#define LeeScreen_Height ([UIScreen mainScreen].bounds.size.height)

@interface LaunchViewController ()<UIScrollViewDelegate>

@property (strong , nonatomic)UIScrollView * scrollView;
@property (strong , nonatomic)UIPageControl * pageControl;

@end

@implementation LaunchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self creatSv];
}


- (void)creatSv
{
#pragma mark ----- scrollView 相关设置
    self.scrollView = [[UIScrollView alloc] initWithFrame:LeeScreen_Frame];
    
    self.scrollView.contentSize = CGSizeMake(LeeScreen_Width * 4, 0);
    self.scrollView.pagingEnabled = YES;
    self.scrollView.bounces = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    
    UIImageView * firstImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, LeeScreen_Width, LeeScreen_Height)];
    firstImgView.image = [UIImage imageNamed:@"2.jpg"];
    [self.scrollView addSubview:firstImgView];
    
    UIImageView * secImgView = [[UIImageView alloc] initWithFrame:CGRectMake(LeeScreen_Width * 1, 0, LeeScreen_Width, LeeScreen_Height)];
    secImgView.image = [UIImage imageNamed:@"5.jpg"];
    [self.scrollView addSubview:secImgView];
    
    UIImageView * thirdImgView = [[UIImageView alloc] initWithFrame:CGRectMake(LeeScreen_Width * 2, 0, LeeScreen_Width, LeeScreen_Height)];
    thirdImgView.image = [UIImage imageNamed:@"10.jpg"];
    [self.scrollView addSubview:thirdImgView];
    
    UIImageView * fouthImgView = [[UIImageView alloc] initWithFrame:CGRectMake(LeeScreen_Width * 3, 0, LeeScreen_Width, LeeScreen_Height)];
    fouthImgView.image = [UIImage imageNamed:@"8.jpg"];
    
//    打开用户交互
    fouthImgView.userInteractionEnabled = YES;
    
    [self.scrollView addSubview:fouthImgView];
    
    UIButton * button  = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [button setTitle:@"Welcome To Snigger" forState:(UIControlStateNormal)];
    [button setFrame:CGRectMake(LeeScreen_Width / 2 - 100, LeeScreen_Height * 4 / 5, 200, 40)];
    [button addTarget:self action:@selector(clickedAc) forControlEvents:(UIControlEventTouchUpInside)];
    [button setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    button.titleLabel.font = [UIFont systemFontOfSize:18.0];
    
    [fouthImgView addSubview:button];
    
    self.scrollView.delegate = self;
    [self.view addSubview:self.scrollView];
    
#pragma mark ----- pageControl 相关设置
    self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(LeeScreen_Width / 2 - 100, LeeScreen_Height * 5 / 6 + 20, 200, 20)];
    self.pageControl.currentPageIndicatorTintColor = [UIColor greenColor];
    self.pageControl.numberOfPages = 4;
    [self.pageControl addTarget:self action:@selector(changePage:) forControlEvents:(UIControlEventTouchUpInside)];
//    self.pageControl.currentPageIndicatorTintColor = [UIColor colorWithRed:44 / 255.0 green:164 / 255.0 blue:101 / 255.0 alpha:1];

    [self.view addSubview:self.pageControl];
    
}
- (void)changePage:(UIPageControl *)sender
{
    [UIView animateWithDuration:0.5 animations:^{
        self.scrollView.contentOffset = CGPointMake(sender.currentPage * LeeScreen_Width, 0);
    }];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.pageControl.currentPage = scrollView.contentOffset.x / LeeScreen_Width;
}

- (void)clickedAc
{
    [self showViewController:[[RootTabBarController alloc] init] sender:self];
}



@end
